﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SP.Docs.Migrator
{
    public partial class Settings : Form
    {
        public static string LogFolder = Application.StartupPath;
        public Settings()
        {
            InitializeComponent();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void cmdSave_Click(object sender, EventArgs e)
        {
            SaveSettings(this.txtFolderSettings.Text);
            Close();
        }
        private void SaveSettings(string value)
        {
            try
            {
                System.IO.StreamWriter wr = new StreamWriter(Path.Combine(Application.StartupPath, "settings.txt"), false);
                wr.WriteLine(value);
                wr.Close();
            }
            catch(Exception ex) 
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private string ReadSettings()
        {
            try
            {
                System.IO.StreamReader sr = new StreamReader(Path.Combine(Application.StartupPath, "settings.txt"), true);
                string path = sr.ReadLine();
                sr.Close();
                return path;
            }
            catch (Exception ex)
            {
                
            }
            return LogFolder;
        }
        private void Settings_Load(object sender, EventArgs e)
        {
            this.txtFolderSettings.Text = ReadSettings();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog flderBrowser = new FolderBrowserDialog();
            if (flderBrowser.ShowDialog() == DialogResult.OK)
            {
                this.txtFolderSettings.Text = flderBrowser.SelectedPath;
            }
        }
    }
}
